<?php

/**
 * XHTML_Title, xhtml_lib
 * 
 * This file contains the source code for the XHTML_Base class.
 * @author Fernando Jimenez Mocobono <fjmcool@gmail.com>
 * @version 0.1
 * @package xhtml_lib
 */

/**
 * The XHTML_Base class is a handler for the base xhtml-strict tag as a part
 * of a xhtml-strict php-handler implementation.
 */
class XHTML_Base {
    
    /**
     * URI to use as the base URI for links in the page.
     *
     * @var string
     */
    protected $href;
    
    /**
     * Unique identifier for the xhtml-base-tag.
     *
     * @var string
     */
    protected $id;
    
    
    // Methods
    
    function __construct($href)
    {
        $this->href = $href;
    }
    
    /**
     * Sets the URI to be used as a base URI for links in the page.
     *
     * @param string $href
     */
    function setHref($href)
    {
        $this->href = $href;
    }
    
    /**
     * Gets the URI that has been set as a base URI for links in the page.
     *
     * @return string
     */
    function getHref()
    {
        return $this->href;
    }
    
    /**
     * Sets the unique identifier.
     *
     * @param string $id
     */
    function setId($id)
    {
        $this->id = $id;
    }
    
    /**
     * gets the unique identifier.
     *
     * @return string
     */
    function getId()
    {
        return $this->id;
    }
    
    
    // Overriding the toString method for a proper implementation.
    
    /**
     * Returns the string representation for echoing the class atributes.
     *
     * @return string
     */
    function toString()
    {
        $auxString = "<base ";
        
        /*
         * Additions of the base own attributes to the return string.
         */
        if (isset($this->href)) {
            $auxString = $auxString."href=\"".$this->href."\" ";
        }
        
        if (isset($this->id)) {
            $auxString = $auxString."id=\"".$this->id."\" ";
        }
        
        $auxString = $auxString."/>\n";
        
        return $auxString;
    }
    
}
?>